package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.BatteryOutEntity
import com.c.ctgproject.entity.guang.HandlerBatteryDetailEntity
import com.c.ctgproject.entity.guang.PartOutDetailEntity
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler

class PartOutDetailAdapter(private val context: Context, private val mList: List<PartOutDetailEntity.DataBean.ItemsBean>) : BaseEmptyRecyclerViewAdapterV2(context, mList) {

    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_part_out_detail_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.partName.text = data.partsName.noDataHandler()
            holder.partCode.text = data.partsCode.noDataHandler()
            holder.partsCount.text = data.partsCount.noDataHandler()
            holder.countUnit.text = data.countUnit.handlerNull()
            holder.weight.text = data.weight.noDataHandler()

            val partsInMethod = when (data.partsInMethod) {
                1 -> "拆解"
                2 -> "散件"
                else -> "暂无数据"
            }
            holder.inType.text = partsInMethod
            holder.oe.text = data.oe.noDataHandler()

        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val partName: TextView = view.findViewById(R.id.partName)
        val partCode: TextView = view.findViewById(R.id.partCode)
        val partsCount: TextView = view.findViewById(R.id.partsCount)
        val countUnit: TextView = view.findViewById(R.id.countUnit)
        val weight: TextView = view.findViewById(R.id.weight)
        val inType: TextView = view.findViewById(R.id.inType)
        val oe: TextView = view.findViewById(R.id.oe)

    }
}